package com.hdcx.Minfresh.view.expandtabview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hdcx.Minfresh.R;
import com.hdcx.Minfresh.adapter.SearchSysParamAdapter;
import com.hdcx.Minfresh.bean.SysParamsBean;

import java.util.List;


/**
 *@Description:expandTab 右 专业特长item
 *@Author:ben
 *@Since:2016年4月13日下午2:33:17
 */
public class SearchTabRight extends RelativeLayout implements ViewBaseAction,MaterialRangeSlider.RangeSliderListener {
     int ps =0;
     Button [] bts;
    OnSelectRightListener listener;

    @Override
    public void onMaxChanged(int newValue) {
        maxPriceTxt.setText("呵呵" + String.valueOf(newValue));
    }

    @Override
    public void onMinChanged(int newValue) {
        minPriceTxt.setText("各个" + String.valueOf(newValue));
    }

    private ListView mListView;
    private List<SysParamsBean> specialtyList;
    private final String[] items = new String[] {"全部特长", "item1", "item2", "item3", "item4", "item5", "item6","item7","item8" };//显示字段
    private final String[] itemsVaule = new String[] { "1", "2", "3", "4", "5", "6","7","8","9" };//隐藏id
    private SearchSysParamAdapter adapter;
    private String mDistance;
    private long selectId;
    private String showText = "地区";
    private Context mContext;
    TextView minPriceTxt,maxPriceTxt;
    MaterialRangeSlider priceSlider;
    String price;
    EditText ed_min,ed_max;


    public String getShowText() {
        return showText;
    }

    public SearchTabRight(Context context) {
        super(context);
        init(context);
    }

    public SearchTabRight(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context);
    }

    public SearchTabRight(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }
    /**
     *@Description: 初始化视图
     *@Author:胡帅
     *@Since: 2016年4月13日下午4:30:26
     *@param context
     */
    private void init(Context context) {
        mContext = context;
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.searchright, this, true);
        ed_min = (EditText) view.findViewById(R.id.ed_min);
        ed_max = (EditText) view.findViewById(R.id.ed_max);
        view.findViewById(R.id.bt_sure).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!=null){
                   String tempmin = ed_min.getText().toString().trim().equals("不限")?"0":ed_min.getText().toString().trim();
                   String tempmax = ed_max.getText().toString().trim().equals("不限")?"0":ed_max.getText().toString().trim();
                    listener.getValue(ps,tempmin+","+tempmax);
                }
            }
        });
        bts = new Button[]{(Button) view.findViewById(R.id.bt_mt),(Button) view.findViewById(R.id.bt_ht),(Button) view.findViewById(R.id.bt_dht)};
        setButtonValue(bts[ps],false);
        for(int i=0;i<bts.length;i++){
            final int finalI = i;
            bts[i].setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    setButtonValue(bts[ps],true);
                    ps= finalI;
                    setButtonValue(bts[ps],false);
                }
            });
        }
        minPriceTxt = (TextView) view.findViewById(R.id.min_price_txt);
        maxPriceTxt = (TextView) view.findViewById(R.id.max_price_txt);
        priceSlider = (MaterialRangeSlider) view.findViewById(R.id.price_slider);
    }
   public void setOKListen(OnSelectRightListener onSelectListener){
       listener =onSelectListener;
   }
    private void setButtonValue(Button bt,Boolean tag) {
        if(tag){
            bt.setEnabled(true);
            bt.setTextColor(getResources().getColor(R.color.line5));
        }else{

            bt.setEnabled(false);
            bt.setTextColor(getResources().getColor(R.color.white));
        }
    }

    public interface OnSelectRightListener {

        public void getValue(int  ps, String showText);
    }
    @Override
    public void hide() {

    }

    @Override
    public void show() {

    }
}

